<extend name="common/layouts"/>


<block name="content">

    <div class="kt-portlet">
        <div class="kt-portlet__head">
            <div class="kt-portlet__head-label">
                <h3 class="kt-portlet__head-title">
                    添加课程
                </h3>
            </div>
        </div>
        <div class="kt-portlet__body">

            <form class="kt-form kt-form--label-right" onsubmit="return false" id="storeForm">
                <div class="kt-portlet__body">

                    <div class="form-group row">
                        <label class="col-2 col-form-label">课程名称</label>
                        <div class="col-10">
                            <input class="form-control" type="text" value="" name="name" required>
                        </div>
                    </div>
                    <div class="form-group row">
                        <label class="col-2 col-form-label">上课时间</label>
                        <div class="col-10">
                            <input class="form-control" type="text" value="" name="time" required>
                        </div>
                    </div>
                    <div class="form-group row">
                        <label class="col-2 col-form-label">上课地点</label>
                        <div class="col-10">
                            <input class="form-control" type="text" value="" name="address" required>
                        </div>
                    </div>

                    <div class="form-group row">
                        <label class="col-2 col-form-label">学分</label>
                        <div class="col-10">
                            <input class="form-control" type="number" value="" name="score" required>
                        </div>
                    </div>

                    <div class="form-group row">
                        <label class="col-2 col-form-label">课时</label>
                        <div class="col-10">
                            <input class="form-control" type="number" value="" name="class_hour" required>
                        </div>
                    </div>
                    <div class="form-group row">
                        <label class="col-2 col-form-label">总人数</label>
                        <div class="col-10">
                            <input class="form-control" type="number" value="" name="limit" required>
                        </div>
                    </div>
                </div>
                <div class="kt-portlet__foot">
                    <div class="kt-form__actions">
                        <div class="row">
                            <div class="col-2">
                            </div>
                            <div class="col-10">
                                <button class="btn btn-success" id="submit">提交</button>
                                <button class="btn btn-secondary">取消</button>
                            </div>
                        </div>
                    </div>
                </div>
            </form>
        </div>

        <!--end::Form-->
    </div>


</block>

<block name="js">
    <script>
        $('#submit').click(function () {
            var loginForm = $('#storeForm').serialize();
            var params = loginForm.split('&');
            for (var i = 0; i < params.length; i++) {
                var item = params[i].split('=');
                if (item[1] == "") {
                    toastr.error('请先将表单填写完整');
                    return;
                }
            }

            $.ajax({
                url: '/home/class/store',
                data: $('#storeForm').serialize(),
                dataType: 'json',
                type: 'post',
                success: function (result) {
                    if (result.code == 0) {
                        toastr.success("新增成功");
                        window.history.go(-1);
                    } else {
                        toastr.error(result.msg);
                        return;
                    }
                }
            })
        })

    </script>
</block>